from langchain_community.tools import WikipediaQueryRun
from langchain_community.utilities import WikipediaAPIWrapper
from pydantic import BaseModel, Field

api_wrapper = WikipediaAPIWrapper(top_k_results=5, doc_content_chars_max=20)

class WikiInputs(BaseModel):
    query: str = Field(description="查询内容")

tool = WikipediaQueryRun(
    name="wiki-tool",
    description="查询wiki",
    args_schema=WikiInputs,
    api_wrapper=api_wrapper,
    # 如果return_direct为True，则直接返回结果，否则返回一个字典，包含结果和元数据
    return_direct=True,
)
print(tool.invoke({"query": "langchain"}))
#打印工具属性
print(f"工具名称:{tool.name}")
print(f"工具描述:{tool.description}")
print(f"工具参数:{tool.args}")
print(f"是否直接返回结果:{tool.return_direct}")